#include <iostream>
using std::cout;
using std::endl;

void test0(){
    int num = 100;
    int num2 = 200;
    //const在*号左边
    //指向常量的指针(pointer to const)
    //能够修改指针的指向
    //但是不能通过指针修改其指向的值
    const int * p = &num;
    /* *p = 1000; */
    p = &num2;
    cout << *p << endl;
    num = 1000;
}

void test1(){
    int num = 100;
    int num2 = 200;
    int const * p = &num;
    /* *p = 1000; */
    p = &num2;
    cout << *p << endl;
    num = 1000;
}

void test2(){
    const int num = 1000;
    //只有指向常量的指针能够指向const常量
    const int * p = &num;
    /* *p = 100; */
    /* num = 100; */
    
    int num2 = 18;
    p = &num2;
}

void test3(){
    int num = 100;
    int num2 = 200;
    //const在*号右边
    //称之为常量指针（const pointer）
    //从右往左读，先读到const，再读到*
    //能够通过指针修改其指向的值
    //但是不能修改指针的指向
    //(即指针变量保存的地址值不会被修改)
    int * const p = &num;
    *p = 1000;
    /* p = &num2; */
    cout << *p << endl;
}

void test4(){
    int num = 100;
    //双重const限定的指针
    const int * const p = &num;
    /* *p = 10; */

    int num2 = 200;
    /* p = &num2; */
}

int main(void){
    test0();
    return 0;
}
